package com.information.manage.basic.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.information.manage.basic.model.entity.DepartmentDO;
import com.information.manage.basic.model.query.DepartmentAddQuery;
import com.information.manage.basic.model.query.DepartmentFindByConditionQuery;
import com.information.manage.basic.model.query.DepartmentUpdateQuery;
import com.information.manage.basic.model.vo.DepartmentListVO;
import com.information.manage.basic.model.vo.DepartmentTreeVO;
import com.information.manage.basic.common.result.Result;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author sy
 * @since 2021-12-27
 */
public interface DepartmentService extends IService<DepartmentDO> {

    /**
     * 添加部门
     * @param departmentAddQuery
     * @return
     */
    Result<Integer> addDepartment(DepartmentAddQuery departmentAddQuery);

    /**
     * 修改部门
     * @param departmentUpdateQuery
     * @return
     */
    Result<Integer> updateDepartment(DepartmentUpdateQuery departmentUpdateQuery);

    /**
     * 删除部门
     * @param departmentIds
     * @return
     */
    Result<Boolean> deleteDepartment(List<Integer> departmentIds);

    /**
     * 部门上下移动
     * @param id
     * @return
     */
    Boolean moveDepartment(Integer id, boolean up);

    /**
     * 查询部门
     * @param id
     * @return 完整部门路径
     */
    String queryDepartmentNameById(Integer id);
    Map<Integer, String> queryDepartmentNameById(List<Integer> id);

    /**
     * 获取部门导入模板
     * @param response
     * @throws IOException
     */
    void downloadExcel(HttpServletResponse response);

    /**
     * 根据父id查询部门list
     * @param id
     * @return
     */
    List<DepartmentListVO> queryDepartmentListById(Integer id);

    List<Integer> getIdsByTypeCollection(Long typeCollection);

    /**
     * 按条件查询部门
     * @param departmentFindByConditionQuery
     * @return 部门树
     */
    List<DepartmentTreeVO> queryDepartmentByCondition(DepartmentFindByConditionQuery departmentFindByConditionQuery);

    /**
     * 根据id获取部门树  从子部门开始找父部门
     * @param departmentIds
     * @return
     */
    List<DepartmentTreeVO> getDepartmentTreeByIds(List<Integer> departmentIds);

    /**
     * 部门导入
     * @param response
     * @param file
     * @return
     */
    Result excelImport(HttpServletResponse response, MultipartFile file);

    /**
     * 部门导出
     * @param response
     */
    void exportExcel(HttpServletResponse response, Long typeCollection, String departmentName);

    /**
     * 生成部门结果集
     * @param ids 子部门id
     * @return  id -》 完整部门路径
     */
    Map<Integer, String> generateParentAndChildDepartment(List<Integer> ids);

    /**
     * 根据部门id获取其所有部门（自身+父部门）
     * list 中存放顺序： 父部门 -》 子部门
     * @param departmentId
     * @return
     */
    List<String> getParentDepartmentListById(Integer departmentId);

    /**
     * 根据部门id查询所有的子部门id
     * @param departmentId
     * @return  当前部门id及其子部门id
     */
    List<Integer> getDepartmentAndChildId(Integer departmentId);

    /**
     * 通过部门完整路径获取部门id
     * @param departmentName
     * @return 部门id
     */
    Integer getDepartmentIdByName(String departmentName);

    /**
     * 根据id获取部门树  从父部门开始找所有子部门 此部门id必须为顶层 即父id为-1
     * @param departmentIds
     * @return
     */
    List<DepartmentTreeVO> getDepartmentTreeByParentIds(List<Integer> departmentIds);

}
